import {
	createStore
} from 'vuex'

import {getMusicLyric} from '@/api/item.js'

export default createStore({
	state: {
		playList: [{
			al: {
				id: 89039055,
				name: "雨爱抖音版",
				pic: 109951164966568500,
				picUrl: "https://p1.music.126.net/2f6UgY8Jc0Dy6jufMdIZeQ==/109951164966568495.jpg",
				pic_str: "109951164966568495"
			},
			id: 1446137141,
			name: "雨爱（抖音版）",
			ar: [{
				name: "灏灏灏仔"
			}]
		}],
		playListIndex: 0,
		isbtnShow: true,
		detailShow: false,
		lyricList: {},
		currentTime: 0,
		duration: 0
	},
	mutations: {
		updateIsbtnShow(state, value) {
			state.isbtnShow = value
		},

		updatePlayList(state, value) {
			state.playList = value
		},

		updatePlayListIndex(state, value) {
			state.playListIndex = value
		},
		
		updateDetailShow(state) {
			state.detailShow = !state.detailShow
		},
		
		updateLyricList(state, value) {
			state.lyricList = value
		},
		
		updateCurrentTime(state, value) {
			state.currentTime = value
		},
		
		updateDuration(state, value) {
			state.duration = value
		},
		
		pushPlayList(state, value) {
			state.playList.push(value)
		}
	},
	actions: {
		async getLyric(context, value) {
			const {data: res} = await getMusicLyric(value)
			context.commit("updateLyricList", res.lrc)
		}
	}
})
